extends NodeState

@export var player: Player
@export var animated_sprite_2D: AnimatedSprite2D
@export var speed: int = 50
signal walk_to_left
signal walk_to_right
var direction: Vector2

var animation_map: Dictionary = {
									Vector2.UP: "walk_back",
									Vector2.RIGHT: "walk_right",
									Vector2.DOWN: "walk_front",
									Vector2.LEFT: "walk_left",
									Vector2.ZERO: "walk_front"
								}


func _on_process(_delta: float) -> void:
	pass


func _on_physics_process(_delta: float) -> void:
	direction = GameInputEvents.movement_input()

	var animation = animation_map.get(direction, "walk_front")
	animated_sprite_2D.play(animation)

	player.velocity = direction * speed
	if direction == Vector2.RIGHT:
		animated_sprite_2D.flip_h = true
		walk_to_right.emit()
	else: if direction == Vector2.LEFT:
		animated_sprite_2D.flip_h = false
		walk_to_left.emit()

	player.move_and_slide()

	if direction != Vector2.ZERO:
		player.player_direction = direction


func _on_next_transitions() -> void:
	if !GameInputEvents.is_movement_input(direction):
		transition.emit("Idle")


func _on_enter() -> void:
	pass


func _on_exit() -> void:
	animated_sprite_2D.stop()
